//package com.aaa.order.controller;
//
//import com.aaa.entity.Order;
//import com.aaa.entity.Product;
//import com.aaa.order.service.OrderService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.cloud.client.ServiceInstance;
//import org.springframework.cloud.client.discovery.DiscoveryClient;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.client.RestTemplate;
//
//import java.util.List;
//import java.util.Random;
//
///**
// * @author ：Username 刘亦辰（59372312@qq.com）
// * @date ：Created in 2022/11/18 1:04
// * @description：
// * @modified By：
// * @version:
// */
//@RestController
//@RequestMapping("/order")
//public class OrderController {
//    @Autowired
//    RestTemplate restTemplate;
//    @Autowired
//    OrderService orderService;
//    @Autowired
//    DiscoveryClient discoveryClient;
//
//    @RequestMapping("show")
//    public String show(){
//        return "ok";
//    }
//
//
//    @GetMapping("/saveOrder")
//    public String saveOrder(Long pid,Integer num) {
//
//        Order order = new Order();
//        //用户得信息可以从登录后获取--Session  redis  jwt
//        order.setUid(1);
//        order.setUsername("刘亦辰");
//        //为订单对象设置商品得信息
//        order.setPid(pid);
//        //远程调用商品微服务提供得接口---后面
//        //List<ServiceInstance> instances = discoveryClient.getInstances("shop-product");
//        //int index = new Random().nextInt(instances.size());
//        //ServiceInstance serviceInstance = instances.get(index);
//        //String uri = serviceInstance.getUri().toString();
//        Product product = restTemplate.getForObject( "http://shop-product/product/getById/"+ pid, Product.class);
//        order.setPname(product.getPname());
//        order.setPprice(product.getPprice());
//        order.setNumber(num);
//        orderService.save(order);
//        return  "下单成功！";
//
//    }
//}
//
